<?php require RCMS_Object_QuickConfig_QuickConfig::PATH_HEADER; ?>
<?php $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/seotoaster.css'); ?>
<?php $this->headLink()->appendStylesheet($this->websiteUrl . 'system/css/swfupload.css'); ?>
<?php $this->headLink()->appendStylesheet($this->websiteUrl . 'system/js/thickbox/thickbox.css'); ?>
<?php echo $this->headLink(); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/jquery/jquery.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/thickbox/thickbox.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/swfupload.queue.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/fileprogress.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/swfupload/handlers.js'); ?>
<?php $this->headScript()->appendFile($this->websiteUrl . 'system/js/plugin/plugin.js'); ?>
<?php echo $this->headScript(); ?>
<script type="text/javascript">
	$(document).ready(function(){
		var url_website = '<?php echo $this->websiteUrl; ?>';
		var settings = {
			flash_url : ""+url_website+"system/js/swfupload/swfupload.swf",
			upload_url: ""+url_website+"sys/backend_plugin/uploadplugin/",
			file_size_limit : "30 MB",
			file_types : "*.zip;",
			file_types_description : "Zip File",
			file_upload_limit : 10,
			file_queue_limit : 0,
			custom_settings : {
				progressTarget : "process",
				cancelButtonId : "btnCancel"
			},
			debug: false,
			button_placeholder_id: 'submit',
			button_image_url: ""+url_website+"system/js/swfupload/<?php echo $this->browsePlugins;//'swf-browse-plugins.png'; ?>",
			button_width: "200",
			button_height: "31",
			button_cursor: SWFUpload.CURSOR.HAND,
			button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,
			button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
			file_queued_handler : fileQueued,
			file_queue_error_handler : fileQueueError,
			file_dialog_complete_handler : fileDialogComplete,
			upload_start_handler : uploadStart,
			upload_progress_handler : uploadProgress,
			upload_error_handler : uploadError,
			upload_success_handler : uploadSuccess,
			upload_complete_handler : uploadComplete,
			queue_complete_handler : queueComplete
		};

		var swfu = new SWFUpload(settings);


		function uploadSuccess(file, serverData){
			var obj = eval('(' + serverData + ')');
			if(obj.error){
				$("#process").html('');
				$("#msg").html(obj.message);
				$("#msg").show();
			} else {
				if(!obj.exist_plugin){
					var pluginNameProcessed = str_replace(" ","-",obj.plugin);
					var	readme = '<a title="Readme.txt" href="javascript:void(0);" style="cursor:pointer;border:none;" onclick="tb_show(\'\',\'<?php echo $this->websiteUrl; ?>sys/backend_plugin/readme/?pluginName='+obj.plugin+'&TB_iframe=true&height=575&width=600\')" >';
					readme += '<img style="border:none;vertical-align:middle;"  src="<?php echo $this->websiteUrl; ?>system/images/icoinfo.gif" alt="readme.txt" />';
					readme += "</a>";


					var cache = '<span id="cache-'+pluginNameProcessed+'" style="font-weight:bold; line-height:20px;">&nbsp;';
					cache +='Cache result?';
					cache +='<input type="checkbox" onchange="cachePlugin(\''+obj.plugin+'\');" />';
					cache +='</span><br/>';

					var str = '<div class="one_theme" style="height:250px;" align="center" id="'+pluginNameProcessed+'-div">';
					str += '<img src="'+obj.preview+'" border="1" width="160" height="170" />';
					str += '<p align="center" style="margin:5px 0px;"><span style="font-weight:bold;">'+obj.plugin+' '+readme+' <img style="vertical-align:middle;cursor:pointer;" src="<?php echo $this->websiteUrl; ?>system/images/ico_delete.gif" onclick="if(confirm(\'Do you really want to delete this plugin?\')) { deletePlugin(\'<?php echo $this->websiteUrl; ?>\', \''+obj.plugin+'\')}else {return false;};" /></span></p>';
					str += '<span id="cache-'+pluginNameProcessed+'" style="font-weight: bold; line-height: 20px;">&nbsp;</span>';
					str += '<p id="pluginstatus-'+pluginNameProcessed+'">';
					str += '<button class="formsubmit" style="font-weight:bold;width:100px;font-size:12px;" onclick="enablePlugin(\'<?php echo $this->websiteUrl; ?>\',\''+obj.plugin+'\')">Enable</button>';
					str += '</p>';
					str += '<p align="right"></p>';
					str += '</p><p style="clear:both;"></p></div>';
					$(".list_themes").append(str);
				}
				try {
					var progress = new FileProgress(file, this.customSettings.progressTarget);
					progress.setComplete();
					progress.setStatus("Complete.");
					progress.toggleCancel(false);
				} catch (ex) {
					this.debug(ex);
				}
			}
		}
	});
</script>
<div id="seotoaster" class="theme">
	<div class="admineditwhat">{%Plugins%}</div>
	<div class="close_window" onclick="parent.tb_remove();parent.location.reload();"></div>
	<div id="uploadtheme">
		<?php if($this->zipExtensionEnabled): ?>
		<form action="javascript:;">
			<input type="button" name="submit" id="submit" value="submit" />
			<input type="button" disabled="disabled" id="btnCancel" value="Cancel All Uploads" onclick="cancelQueue(swfu);" style="margin-left: 2px; font-size: 8pt; height: 29px; display:none;">
		</form>
		<div id="process"></div>
		<div id="msg" class="errors" style="display: none;" onclick="this.style.display='none';"></div>
		<?php else: ?>
			<div class="errors" style="top:35;left:50px;width:450px;padding:20px;" onclick="this.style.display='none';">
			Your server does not have ZIP extension installed. Please install ZIP extension or upload your new plugin by FTP.</div>
		<?php endif; ?>
	</div>

	<div id="plugin-errors" class="errors" style="display:none;">
		<ul>
			<li id="installation-error" style="display:none;" class="error">'install.sql' contains errors and prevent successful instalation!</li>
			<li id="uninstallation-error"  style="display:none;" class="error">'uninstall.sql' contains errors and prevent successful instalation!</li>
			<li id="installsql" style="display:none;" class="error">Plugin must contain 'install.sql'</li>
		</ul>
	</div>

	<h2 align="center">{%Plugins list%}</h2>
	<!-- upload things -->

	<!-- end upload things -->
	<form action="javascript:void(0);" method="post" id="plugins" name="plugins">
		<div class="list_themes">
			<?php if(!empty($this->listPlugins) && is_array($this->listPlugins)): ?>
				<?php foreach($this->listPlugins as $plugin):?>
					<?php if(!empty($plugin) && $plugin['name'] != '' && $plugin['name'] != 'desktop.ini'): ?>
						<div class="one_theme" style="height:250px;" align="center" id="<?php echo $plugin['name'];?>-div">
							<img src="<?php echo $plugin['previewImage']; ?>" border="1" width="160" height="170" alt="plugin preview" />
							<p align="center" style="margin:5px 0px;">
								<span style="font-weight:bold;">
									<?php echo $plugin['name']; ?>
									<a title="Readme.txt" href="javascript:void(0);" style="cursor:pointer;border:none;" onclick="tb_show('','<?php echo $this->websiteUrl; ?>sys/backend_plugin/readme/?pluginName=<?php echo $plugin['name'];?>&TB_iframe=true&height=575&width=600');"><img style="border:none;vertical-align:middle;"  src="<?php echo $this->websiteUrl; ?>system/images/icoinfo.gif" alt="readme.txt" /></a>
									<img style="vertical-align:middle;cursor:pointer;" src="<?php echo $this->websiteUrl; ?>system/images/ico_delete.gif" onclick="if(confirm('Do you really want to delete this plugin?')) { deletePlugin('<?php echo $this->websiteUrl; ?>', '<?php echo $plugin['name']; ?>')}else {return false;};" />
								</span>
							</p>
							<span id="cache-<?php echo $plugin['name']; ?>" style="font-weight:bold; line-height:20px;">&nbsp;
								Cache result?
								<input type="checkbox" <?php echo ($plugin['cache']) ? 'checked="checked"' : ''; ?> onchange="cachePlugin('<?php echo $plugin['name'];?>');" />
							</span>
							<p id="pluginstatus-<?php echo $plugin['name']; ?>">
									<?php if($plugin['status']=='disabled'): ?>
										<button id="plugbutton_<?php echo $plugin['name']; ?>" class="formsubmit" style="font-weight:bold;width:100px;font-size:12px;" onclick="enablePlugin('<?php echo $this->websiteUrl?>','<?php echo trim($plugin['name']);?>')">{%Enable%}</button>
									<?php else: ?>
										<button id="plugbutton_<?php echo $plugin['name']; ?>" class="formsubmit" style="font-weight:bold;width:100px;font-size:12px;" onclick="disablePlugin('<?php echo $this->websiteUrl?>','<?php echo trim($plugin['name']);?>')">{%Disable%}</button>
									<?php endif; ?>
							</p>
						</div>
<!--						<p style="clear:both;"></p>-->
					<?php endif; ?>
				<?php endforeach; ?>
			<?php endif; ?>
		</div>
		<input type="hidden" id="hid-main-wsurl" name="hid-main-wsurl" value="<?php echo $this->websiteUrl; ?>" />
	</form>
</div>